//
//  QuestionDealView.m
//  TeamInformatization
//
//  Created by bigger on 2019/4/3.
//  Copyright © 2019年 SPIC. All rights reserved.
//

#import "QuestionDealView.h"

@interface QuestionDealView ()

// 延期页面
@property (nonatomic, strong) UIView *workDelayView;
// 转移页面
@property (nonatomic, strong) UIView *workDeliverView;

@end


@implementation QuestionDealView

- (instancetype)init
{
    if (self = [super init]) {
        self.backgroundColor = [UIColor whiteColor];
        [self creatViews];
    }
    return self;
}


- (void)creatViews
{
    SimpleLabel *titleLabel = [SimpleLabel initWithText:@"操作" TextColor:kTitleTextColor TextFont:[UIFont fontWithName:@"PingFangSC-Medium" size: 15] TextAlignment:NSTextAlignmentLeft];
    [self addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(15 * kScaleWidth);
    }];
    
    float spaceWidth = (kScreenWidth - 282 * kScaleWidth) / 2. + 84 * kScaleWidth;
    NSArray *textArray = @[@"接受", @"延期", @"转移"];
    for (int i = 0; i < 3; i++) {
        UIButton *selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [selectButton setTitleColor:kSetRGBColor(102, 102, 102, 1) forState:UIControlStateNormal];
        [selectButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [selectButton setTitle:textArray[i] forState:UIControlStateNormal];
        selectButton.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Regular" size: 15];
        selectButton.tag = 2400 + i;
        [selectButton addTarget:self action:@selector(selectDealWay:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:selectButton];
        [selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(titleLabel.mas_bottom).offset(20 * kScaleWidth);
            make.left.mas_equalTo(15 * kScaleWidth + spaceWidth * i);
            make.size.mas_equalTo(CGSizeMake(84 * kScaleWidth, 30 * kScaleWidth));
        }];
        selectButton.layer.masksToBounds = YES;
        selectButton.layer.cornerRadius = 5.;
        selectButton.layer.borderWidth = 1.;
        selectButton.layer.borderColor = kCommonBGGaryColor.CGColor;
        
    }
    
    // 分割线
    UILabel *lineLabel = [[UILabel alloc] init];
    lineLabel.backgroundColor = kCommonBGGaryColor;
    [self addSubview:lineLabel];
    [lineLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(104 * kScaleWidth);
        make.left.mas_equalTo(15 * kScaleWidth);
        make.right.mas_equalTo(-15 * kScaleWidth);
        make.height.mas_equalTo(0.5);
    }];
}

// 选择处理方式
- (void)selectDealWay:(UIButton *)sender
{
    for (int i = 2400; i < 2403; i++) {
        UIButton *button = [self viewWithTag:i];
        button.selected = NO;
        [button setBackgroundColor:[UIColor whiteColor]];
        button.layer.borderWidth = 1.;
        button.layer.borderColor = kCommonBGGaryColor.CGColor;
    }
    
    sender.selected = YES;
    [sender setBackgroundColor:kCommonRedColor];
    sender.layer.borderWidth = 0;
    
    switch (sender.tag) {
        case 2400: {
            [_workDelayView setHidden:YES];
            [_workDeliverView setHidden:YES];
            break;
        }
        case 2401: {
            [_workDeliverView setHidden:YES];
            [[self workDelayView] setHidden:NO];
            break;
        }
        case 2402: {
            [_workDelayView setHidden:YES];
            [[self workDeliverView] setHidden:NO];
            break;
        }
        default:
            break;
    }
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(getSelectNum:DataDict:withQuestionDealView:)]) {
        //代理存在且有这个transButIndex:方法
        [self.delegate getSelectNum:(int)(sender.tag - 2400)  DataDict:nil withQuestionDealView:self];
    }
    
}


// 延期
- (UIView *)workDelayView
{
    if (!_workDelayView) {
        _workDelayView = [[UIView alloc] init];
        _workDelayView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_workDelayView];
        [_workDelayView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(105 * kScaleWidth);
            make.left.right.mas_equalTo(0);
        }];
    
        NSArray *textArr = @[@"延期原因:", @"延期期限:"];
        for (int i = 0; i < 2; i++) {
            SimpleLabel *textLabel = [SimpleLabel initWithText:textArr[i] TextColor:kTitleTextColor TextFont:kFont(PFSCRegular, 15) TextAlignment:NSTextAlignmentLeft];
            [_workDelayView addSubview:textLabel];
            [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(32 * kScaleWidth + 50 * kScaleWidth * i);
                make.left.mas_equalTo(15 * kScaleWidth);
            }];
            
            // 分割线
            UILabel *lineLabel = [[UILabel alloc] init];
            lineLabel.backgroundColor = kCommonBGGaryColor;
            [_workDelayView addSubview:lineLabel];
            [lineLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(textLabel.mas_bottom).offset(12 * kScaleWidth);
                make.left.mas_equalTo(15 * kScaleWidth);
                make.right.mas_equalTo(-15 * kScaleWidth);
                make.height.mas_equalTo(0.5);
            }];
        }
    }
    return _workDelayView;
}


// 转移
- (UIView *)workDeliverView
{
    if (!_workDeliverView) {
        _workDeliverView = [[UIView alloc] init];
        _workDeliverView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_workDeliverView];
        [_workDeliverView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(105 * kScaleWidth);
            make.left.right.mas_equalTo(0);
        }];
        
        SimpleLabel *textLabel = [SimpleLabel initWithText:@"转移给:" TextColor:kTitleTextColor TextFont:kFont(PFSCRegular, 15) TextAlignment:NSTextAlignmentLeft];
        [_workDeliverView addSubview:textLabel];
        [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(32 * kScaleWidth);
            make.left.mas_equalTo(15 * kScaleWidth);
        }];
        
        //
        UIButton *selectReplacementButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [selectReplacementButton setImage:[UIImage imageNamed:@"分组"] forState:UIControlStateNormal];
        [selectReplacementButton addTarget:self action:@selector(selectReplacementAction:) forControlEvents:UIControlEventTouchUpInside];
        [_workDeliverView addSubview:selectReplacementButton];
        [selectReplacementButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-15 * kScaleWidth);
            make.centerY.mas_equalTo(textLabel);
            make.size.mas_equalTo(CGSizeMake(30, 30));
        }];
        //
        SimpleLabel *replacementLabel = [SimpleLabel initWithText:@"请选择转移人:" TextColor:kSetRGBColor(153, 153, 153, 1) TextFont:kFont(PFSCRegular, 13) TextAlignment:NSTextAlignmentLeft];
        [_workDeliverView addSubview:replacementLabel];
        [replacementLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(selectReplacementButton.mas_left).offset(-10 * kScaleWidth);
            make.centerY.mas_equalTo(textLabel);
        }];
        
        // 分割线
        UILabel *lineLabel = [[UILabel alloc] init];
        lineLabel.backgroundColor = kCommonBGGaryColor;
        [_workDeliverView addSubview:lineLabel];
        [lineLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(textLabel.mas_bottom).offset(12 * kScaleWidth);
            make.left.mas_equalTo(15 * kScaleWidth);
            make.right.mas_equalTo(-15 * kScaleWidth);
            make.height.mas_equalTo(0.5);
        }];
        
    }
    return _workDeliverView;
}


// 选择转移人
- (void)selectReplacementAction:(UIButton *)sender
{
    NSLog(@"选择");
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
